#!/bin/bash

echo "================================================"
echo "医学文献智能检索与摘要平台 - 客户端启动脚本"
echo "================================================"
echo ""

echo "[1/2] 检查API服务器是否运行..."
if curl -s http://localhost:8000/health > /dev/null 2>&1; then
    echo "API服务器已在运行 ✓"
else
    echo "API服务器未启动，正在启动..."
    echo ""
    python run_server.py &
    SERVER_PID=$!
    echo "等待10秒让API服务器启动..."
    sleep 10
    echo "API服务器已启动 (PID: $SERVER_PID)"
fi

echo ""
echo "[2/2] 启动桌面客户端..."
python client/app.py

# 如果后台启动了服务器，等待用户关闭客户端后停止服务器
if [ ! -z "$SERVER_PID" ]; then
    wait $SERVER_PID
fi
